<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/23
 * Time: 13:51
 */

namespace app\admin\controller;
use       think\Controller;
use       think\Db;
use       think\Request;

class Examine extends Controller
{

    //待审核列表
    public function examine_list()
    {
     $list=Db::query('select *from x_user,x_order where x_user.id=x_order.user_id and x_order.audit_sta=0');
     $this->assign('list',$list);
     return $this->fetch();

    }

    //欠款列表
    public function arrears_list()
    {
        $list=Db::query('select *from x_user,x_order where x_user.id=x_order.user_id and x_order.borrow_status=1');
        $this->assign('list',$list);
        return $this->fetch();

    }

    //审核通过
    public function examine_pass()
    {
        $OderNum=Request::instance()->post('order_num');
        $Data   = array('audit_sta'=>1, 'borrow_status'=>1);
        //更新状态
        $Offest =Db::table('x_order')->where('order_num=:order_num',['order_num'=>$OderNum])->update($Data);
        //返回操作数据库状态
        if($Offest){return json(['code'=>1]);}else{return json(['code'=>0]);}
    }

    //审核拒绝
    public function examine_stop()
    {
        $OderNum=Request::instance()->post('order_num');
        $Data   = array('audit_sta'=>1, 'borrow_status'=>-1);
        //更新状态
        $Offest =Db::table('x_order')->where('order_num=:order_num',['order_num'=>$OderNum])->update($Data);
        //返回操作数据库状态
        if($Offest){return json(['code'=>1]);}else{return json(['code'=>0]);}
    }
    //改变借款状态
    public function ChangeStatus_borrow()
    {
        $OderNum=Request::instance()->post('order_num');
        $Data   = array('borrow_status'=>1);
        //更新状态
        $Offest =Db::table('x_order')->where('order_num=:order_num',['order_num'=>$OderNum])->update($Data);
        //返回操作数据库状态
        if($Offest){return json(['code'=>1]);}else{return json(['code'=>0]);}
    }

    //验证4元素是不是正确信息
    public function message_prov()
    {
        $User_id=Request::instance()->post('order_num');
        //根据opendid查出相关的信息
        $List   =Db::query('select *from x_user where id=:id',['id'=>$User_id]);
        $Key    ="b89bc6aa53d840cab09e2dce6b1ce7c3";
        //$URL= http://apis.haoservice.com/creditop/BankCardQuery/QryBankCardBy4Element?accountNo=6652366994848572&name=?&idCardCode=5444619919161&bankPreMobile=18883180380&key=b89bc6aa53d840cab09e2dce6b1ce7c3
        $Url    ="http://apis.haoservice.com/creditop/BankCardQuery/QryBankCardBy4Element?accountNo={$List[0]['bankcard']}&name=nei&idCardCode={$List[0]['idcard']}&bankPreMobile={$List[0]['mobile']}&key={$Key}";
        $Result =json_decode($this->curl($Url),true);//生成关联数组
        if($Result['result']['messagetype']!=0) {return  json(['code'=>0]);}
        return json(['code'=>1]);

    }
    //启用curl 模仿游览器使用https协议访问链接
    public function curl($url,$data=null)
    {
        $ch = curl_init();

        curl_setopt_array($ch, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET",
        ));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//不检测服务器的证书是否由正规浏览器认证过的授权CA颁发
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//不检测服务器的域名与证书上的是否一致
        $response = curl_exec($ch);
        $err = curl_error($ch);

        curl_close($ch);

        if ($err) {
            echo "cURL Error #:" . $err;
        } else {
            return $response;
        }
    }

}